package cn.wowjoy.pda.android_pharmacy.ui.activity.hospital.send;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.view.View;

import cn.wowjoy.pda.android_pharmacy.R;
import cn.wowjoy.pda.android_pharmacy.common.core.BaseActivity;
import cn.wowjoy.pda.android_pharmacy.common.utils.NetWorkUtils;
import cn.wowjoy.pda.android_pharmacy.common.utils.PreferenceManager;
import cn.wowjoy.pda.android_pharmacy.common.widget.CreateDialog;
import cn.wowjoy.pda.android_pharmacy.common.widget.MyToast;
import cn.wowjoy.pda.android_pharmacy.databinding.ActivityInHospitalSendDetailBinding;
import cn.wowjoy.pda.android_pharmacy.mvvm.presenter.InHospitalSendDetailPresenter;
import cn.wowjoy.pda.android_pharmacy.mvvm.vm.InHospitalSendDetailViewModel;

public class InHospitalSendDetailActivity extends BaseActivity<ActivityInHospitalSendDetailBinding,InHospitalSendDetailViewModel,InHospitalSendDetailPresenter> implements InHospitalSendDetailPresenter.OnSubmitHospitalResult {

    @Override
    protected void init(Bundle savedInstanceState) {
        binding.setPresenter(presenter);
        binding.setViewModel(viewModel);


        binding.medicineDetailTitle.titleTextTv.setText("送药");
        binding.medicineDetailTitle.titleBackLl.setVisibility(View.VISIBLE);
        binding.rvMedicineDetail.setLayoutManager(new LinearLayoutManager(this));
        binding.medicineDetailTitle.titleBackLl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
               finish();
            }
        });
        presenter.registeOnSubmitResultListener(this);
        binding.medicineDetailTitle.titleBackTv.setText("");
        //开单号
        binding.tvMedicineDetailChufanghao.setText("NO: "+presenter.DJJLID);
        //开单科室
        binding.tvMedicineDetailPatientRoom.setText(presenter.FitstData.get(0).getRYBQMC());
        //开单时间
        binding.tvMedicineDetailTime.setText("开单时间: "+presenter.FitstData.get(0).getFYCZSJ());
        //扫码广播收到 准备跳转 传递数据
        binding.btMedicineDetailStart.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(NetWorkUtils.isWifi(InHospitalSendDetailActivity.this)){
                    presenter.sendUpdate("1", PreferenceManager.getInstance().getLUserId());
                }else{
                    CreateDialog.failDialog3(InHospitalSendDetailActivity.this,"错误","当前网络不可用，请检查你的网络设置");
                }
            }
        });
        //TODO:获取RecycleView的总条目数
        if(presenter.FitstData != null){
            binding.tvMedicineDetailTotalNum.setText("共"+ presenter.FitstData.size()+"种药品");
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
//        PreferenceManager.getInstance().setHospitalTakeProgressTotal("0");
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_in_hospital_send_detail;
    }

    @Override
    protected Class<InHospitalSendDetailPresenter> getPresenterClass() {
        return InHospitalSendDetailPresenter.class;
    }

    @Override
    protected Class<InHospitalSendDetailViewModel> getViewModelClass() {
        return InHospitalSendDetailViewModel.class;
    }

    @Override
    public void submitSuccess() {
        new MyToast(InHospitalSendDetailActivity.this).showinfo("送药成功");
        startActivity(new Intent(InHospitalSendDetailActivity.this,InHospitalSendIndexActivity.class));
        finish();
    }

    @Override
    public void submitFail(String errMsg) {
        new MyToast(InHospitalSendDetailActivity.this).showinfo("送药失败");
        startActivity(new Intent(InHospitalSendDetailActivity.this,InHospitalSendIndexActivity.class));
        finish();
    }
}
